/**
 * 
 */
package xiaojian.toolkit.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import com.google.common.collect.Lists;

/**
 * @author isdom
 *
 */
public class StringUtils {
	static public List<String> line2list(String line) {
		List<String> ret = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer(line, ",", false);
		while (st.hasMoreTokens()) {
			ret.add(st.nextToken().trim());
		}

		return ret;
	}

	static public String[] line2array(String line) {
		return line2list(line).toArray(new String[0]);
	}

	public static Map stringToMap(String value) {
		Map map = new HashMap();
		if (value == null)
			return map;
		for (String s : value.split(",")) {
			String[] m = s.split(":");
			if (m.length == 2)
				map.put(m[0].trim(), m[1].trim());
		}

		return map;
	}

	public static List<String> stringToList(String value) {
		if (value == null) {
			return Lists.newArrayList();
		}
		return Lists.newArrayList(value.split(","));
	}
}
